Index=MLayout.extend();
Index.define({
  id: 0,
  layoutOptions: {
      contentSelector: ".lcontent",
      center__paneSelector: ".inner-center",
      west__paneSelector:   ".inner-west",
      west__size:           .28,
      west__closable:	      false,
      west__draggable:	  false,
      west__resizable: false,
      east__paneSelector:   ".inner-east",
      east__size:           .28,
      east__closable:	      false,
      east__draggable:	  false,
      east__resizable: false,
      spacing_open:         4,
      spacing_closed:       4,
      //resizeWhileDragging:  true,
      onopen: function() {updateSize();},
      onclose: function() {updateSize();},
      onresize: function() {updateSize();}
  },      
  initialize: function(){
      $('.maincfg1,.maincfg2,.maincfg3').button({text: false});
      var tmpConfMap={
        main: {},
	identification: {},
	provider: {}
      };
      this.refresh();

      
      this.id++;
    },
  refresh: function(){
      $('#privileges_display').css({"height": (window.innerHeight-326)+"px"});
      $( "a.plbutton" ).button();
      $('.maincfg1,.maincfg2,.maincfg3, .start-stop').button({text: false});
      $('.toolbar a').tipsy({fade: true, offset:3, opacity: 1, gravity: 'nw'});
      $( "a.save-config" ).button();
      $( "#nav li a" ).button();
      $( ".nb-container p a" ).button();
      var tabContainers = $('div.tabs-left > div');
      tabContainers.hide().filter(':first').show();
      $('div.toolbar a').click(function () {
	  if(this.id!="saveConf"){
	    tabContainers.hide();
	    tabContainers.filter(this.hash).show();
	  }else{
	    saveConf(cTab);
	  }
	}).filter(':first').click();
      defaultInit();
    }
  });


SrsManager=Class.create({
    initializeWindow: function(){
	$.ajax({
	    url: "./Projections",
	    complete: function(xml,status){
		if(!$('#SrsManager-dialog')[0])
		    $("body").append('<div id="SrsManager-dialog" title="SRS Manager"></div>');
		$('#SrsManager-dialog').html("");
		$('#SrsManager-dialog').append(xml.responseText);
		$('#SrsManager-dialog').window({
		    width: 325,
		    height: 220,
		    maximizable:false,
		    resizable: false
		});

	    }
	});
    }
});

var tabs={};
var cTab;

function loadTab(){
    cTab=arguments[0];
    tabs[cTab]="";
    $.ajax({
      cache: false,
      type: "GET",
      url: System.zooUrl+"?metapath=configuration&service=WPS&version=1.0.0&request=Execute&Identifier=GetConf&DataInputs=section="+arguments[0]+"&RawDataOutput=Result",
      dataType: "xml",
      complete: function(xml,status) {
          $('#progress_bar .ui-progress').css('width', '65%');
          eval("var tmp="+xml.responseText+";");
          tabs[cTab]=tmp;
          $('#progress_bar .ui-progress').css('width', '85%');
          for(var t in tmp)
              if($mj(t))
                  $mj(t).value=tmp[t];
          $('#progress_bar .ui-progress').css('width', '95%');
          $('#progress_bar .ui-progress').animateProgress(100, function() {
                $('#progress_bar .ui-progress').fadeOut(1000);
                });
	  endLoading();

        }
      });
}  

function saveConf(){
  var args={};
  var tmp=[];
  tmp[tmp.length]={name: "section",value: arguments[0],dataType: "string"};
  for(var i in tabs[arguments[0]]){
    if($("#"+i)[0]){
      tmp[tmp.length]={name: i,value: $("#"+i)[0].value,dataType: "string"};
    }
  }
  try{
   var data=WPSGetHeader("SaveConf")+WPSGetInputs(tmp)+WPSGetOutput({name: "Result"})+WPSGetFooter();
    $.ajax({
      type: "POST",
	  url: System.zooUrl+"?metapath=configuration",
	  contentType: 'text/xml',
	  data: data,
	  complete: function(xml,status) {
	  try{
	    loadTab(cTab);
	  }catch(e){alert(e);}
        }
      });
  }catch(e){alert(e);}
  return false;
}


MapMintDBManager=Class.create({
    accessDST: function(){
	$.ajax({
	    type: "GET",
	    url: "./Distiller/PgWindow;dataStore="+$('#browser_selected_dsName').val(),
	    complete: function(xml,status) {
		if(!$('#databaseAccess-dialog')[0])
		    $('body').append('<div id="databaseAccess-dialog" title="'+System.messages["Database Access"]+'"></div>');
		$( "#databaseAccess-dialog" ).html("").append(xml.responseText);
		$( "#databaseAccess-dialog" ).window({
		    height: 500,
		    width: 720,
		    minimizable:false,
		    maximizable:false,
		    resizable: false
		});
	    }
	});

    },

    validTupleEditing: function(){
	var params="{";
	var clause="";
	$("#pg_editor").find('input').each(function(){
	    if(this.id){
		if(this.id=="clause")
		    clause=this.id.replace(/pg_tuple_/g,"")+"="+(this.value==""?"NULL":this.value);
		else{
		    params+=(params!="{"?",":"")+'"'+this.id.replace(/pg_tuple_/g,"")+'":"'+(this.value==""?"NULL":(this.type=="checkbox"?(this.checked?'t':'f'):$(this).val()))+'"';
		}
	    }
	});
	$("#pg_editor").find('textarea').each(function(){
	    params+=(params!="{"?",":"")+'"'+this.id.replace(/pg_tuple_/g,"")+'":"'+$(this).val().replace(/\r\n|\r|\n/g,"\\\\n")+'"'
	});
	$("#pg_editor").find('select').each(function(){
	    params+=(params!="{"?",":"")+'"'+this.id.replace(/pg_tuple_/g,"")+'":"'+$(this).val()+'"'
	});
	params+="}"
	var request=WPSGetHeader("editTuple");
	var dataInputs=[];
	dataInputs[dataInputs.length]={"name": "dataStore","value": System.dataStore,"dataType": "string"};
	dataInputs[dataInputs.length]={"name": "table","value": System.table,"dataType": "string"};
	if($('#clause').val() && $('#clause').val()!="true")
	    dataInputs[dataInputs.length]={"name": "clause","value": $('#clause').val(),"dataType": "string"};
	dataInputs[dataInputs.length]={"name": "obj","value": params,"dataType": "string"};
	request+=WPSGetInputs(dataInputs)+WPSGetOutput({"name":"Result"})+WPSGetFooter();
	$.ajax({
	    type: "POST",
	    url: System.zooUrl+"?metapath=datastores/postgis",
	    data: request,
	    contentType: "text/xml",
	    complete: function(xml,status) {
		if(checkWPSResult(xml,false)){
		    $( "#databaseEditor-dialog" ).window("close");
		    MapMintDBManager.loadTable({"schema":System.dataStore,"table":System.table});
		}
	    }
	});
    },

    refreshTablesList: function(){
	$.ajax({
	    type: "GET",
	    url: System.zooUrl+"?metapath=datastores/postgis&service=WPS&version=1.0.0&request=Execute&Identifier=listTables&DataInputs=dataStore="+$('#browser_selected_dsName').val()+";schema="+$('#pg_schema').val()+"&RawDataOutput=Result",
	    complete: function(xml,status) {
		if(checkWPSResult(xml,false)){
		    var tmp=eval(xml.responseText);
		    $("#pg_table").html('<option value="-1">'+System.messages["Choose"]+'</option>');
		    for(i=0;i<tmp.length;i++)
			$("#pg_table").append('<option value="'+tmp[i][0]+'">'+tmp[i][1]+'</option>');
		}
	    }
	});	
    },

    editTuple: function(){
	var cnt=0;
	System.tupleID="";
	$('#pg_table_display tr').each(function(){
	    if($(this).hasClass('trSelected')){
		System.tupleID=this.id.replace(/row/g,"");
	    }
	    cnt+=1;
	});
	$.ajax({
	    type: "GET",
	    url: "./Distiller/PgEditorWindow;"+System.args+(System.tupleID!=""?";clause="+System.pkey+"="+System.tupleID:""),
	    complete: function(xml,status) {
		if(checkWPSResult(xml,false)){
		if(!$('#databaseEditor-dialog')[0])
		    $('body').append('<div id="databaseEditor-dialog" title="'+System.messages["Database Editor"]+'"></div>');
		$( "#databaseEditor-dialog" ).html("").append(xml.responseText);
		$( "#databaseEditor-dialog" ).window({
		    minimizable:false,
		    maximizable:false,
		    resizable: false
		});
		}
	    }
	});
    },

    ogcInformations: function(){
	var cnt=0;
	System.tupleID="";
	$('#pg_table_display tr').each(function(){
	    if($(this).hasClass('trSelected')){
		System.tupleID=this.id.replace(/row/g,"");
	    }
	    cnt+=1;
	});
	$.ajax({
	    type: "GET",
	    url: "./Distiller/ogcInformations;"+System.args+(System.tupleID!=""?";clause="+System.pkey+"="+System.tupleID:""),
	    complete: function(xml,status) {
		if(checkWPSResult(xml,false)){
		/*if(!$('#ogcInformations-dialog')[0])
		    $('body').append('<div id="ogcInformations-dialog" title="'+System.messages["Privileges"]+'"></div>');*/
		$( "#privileges_display" ).html("").append(xml.responseText);
		$( "#privileges_display .plbutton" ).button();
		/*$( "#ogcInformations-dialog" ).window({
		    height: 250,
		    minimizable:false,
		    maximizable:false,
		    resizable: false
		});*/
		}
	    }
	});
    },

    ogcPrivileges: function(){
	var cnt=0;
	System.tupleID="";
	$('#pg_table_display tr').each(function(){
	    if($(this).hasClass('trSelected')){
		System.tupleID=this.id.replace(/row/g,"");
	    }
	    cnt+=1;
	});
	System.ctbl=arguments[0];
	    
	var reg=new RegExp(System.prefix+"servers","g");
	$.ajax({
	    type: "GET",
	    url: "./Distiller/PrivilegesEditorWindow;"+System.args.replace(reg,arguments[0])+(System.tupleID!=""?";clause="+System.pkey+"="+System.tupleID:"")+";"+arguments[1],
	    complete: function(xml,status) {
		if(checkWPSResult(xml,false)){
		    if($('#ogcPrivileges-dialog')[0]){
			$( "#ogcPrivileges-dialog" ).window('close');
			$( "#ogcPrivileges-dialog" ).remove();
		    }
		$('body').append('<div id="ogcPrivileges-dialog" title="'+System.messages[(System.ctbl==System.prefix+"layer_privileges"?"Layer":"Server")+" Privileges"]+'"></div>');
		$( "#ogcPrivileges-dialog" ).html("").append(xml.responseText);
		$( "#ogcPrivileges-dialog" ).window({
		    height: 325,
		    minimizable:false,
		    maximizable:false,
		    resizable: false
		});
		    $("#ogc_priv").flexigrid();
		}
	    }
	});
    },
    validOgcPrivileges: function(){
	var params="{";
	var clause="";
	var tuple=[];
	var tuples=[];
	var tupleId=0;
	$("#ogc_priv").find('tr').each(function(){
	    tuple+=[{}];
	    System.pTable=System.prefix+"server_privileges";
	    $(this).find('input').each(function(){
		if(this.id){
		    if(this.id=="clause")
			clause=this.id.replace(/pg_tuple_/g,"")+"="+(this.value==""?"NULL":this.value);
		    else{
			tuple[tupleId][this.id.replace(/pg_tuple_/g,"")]=$(this).val();
			params+=(params!="{"?",":"")+'"'+this.id.replace(/pg_tuple_/g,"")+'":"'+(this.value==""?"NULL":(this.type=="checkbox"?(this.checked?'t':'f'):$(this).val()))+'"';
		    }
		}
	    });
	    $(this).find('textarea').each(function(){
		if(this.id.replace(/pg_tuple_/g,"")=="entity")
		    System.pTable=System.prefix+"layer_privileges";
		params+=(params!="{"?",":"")+'"'+this.id.replace(/pg_tuple_/g,"")+'":"'+(this.value==""?"NULL":$(this).val())+'"';
		tuple[tupleId][this.id.replace(/pg_tuple_/g,"")]=$(this).val();
	    });
	    $(this).find('select').each(function(){
		params+=(params!="{"?",":"")+'"'+this.id.replace(/pg_tuple_/g,"")+'":"'+(this.value==""?"NULL":$(this).val())+'"';
		tuple[tupleId][this.id.replace(/pg_tuple_/g,"")]=$(this).val();
	    });
	    tuples[tupleId]=JSON.parse(params+"}");
	    params="{";
	    tupleId+=1;
	});
	var request=WPSGetHeader("editPriv");
	var dataInputs=[];
	dataInputs[dataInputs.length]={"name": "dataStore","value": System.dataStore,"dataType": "string"};
	dataInputs[dataInputs.length]={"name": "table","value": System.pTable,"dataType": "string"};
	if($('#clause').val() && $('#clause').val()!="true")
	    dataInputs[dataInputs.length]={"name": "clause","value": $('#clause').val(),"dataType": "string"};
	dataInputs[dataInputs.length]={"name": "obj","value": JSON.stringify(tuples),"dataType": "string"};
	request+=WPSGetInputs(dataInputs)+WPSGetOutput({"name":"Result"})+WPSGetFooter();
	$.ajax({
	    type: "POST",
	    url: System.zooUrl+"?metapath=datastores/postgis",
	    data: request,
	    contentType: "text/xml",
	    complete: function(xml,status) {
		if(checkWPSResult(xml,false)){
		    $( "#ogcPrivileges-dialog" ).window("close");
		}
	    }
	});
    },

    deleteTuple: function(){
	$('#pg_table_display tr').each(function(){
	    if($(this).hasClass('trSelected')){
		System.tupleID=this.id.replace(/row/g,"");
	    }
	});
	$.ajax({
	    type: "GET",
	    url: System.zooUrl+"?metapath=datastores/postgis&service=WPS&version=1.0.0&request=Execute&Identifier=deleteTuple&DataInputs="+System.args+";clause="+System.pkey+"="+System.tupleID+"&RawDataOutput=Result",
	    complete: function(xml,status) {
		if(checkWPSResult(xml,false)){
		    MapMintDBManager.loadTable();		    
		}
	    }
	});
    },

    toggleTool: function(){
	alert('ok toggleTool');
    },

    loadTable: function(){
	if(arguments.length==0){
	    System.dataStore=$('#browser_selected_dsName').val();
	    System.table=$('#pg_table').val();
	}
	else{
	    System.dataStore=arguments[0]["schema"];
	    System.table=arguments[0]["table"];
	}
	if(!$("#databaseAccess-dialog")[0])
	    System.tbld="tbl_content";
	else
	    System.tbld="databaseAccess-dialog";
	System.args="dataStore="+System.dataStore+";table="+System.table;
	$.ajax({
	    type: "GET",
	    url: System.zooUrl+"?metapath=datastores/postgis&service=WPS&version=1.0.0&request=Execute&Identifier=getTableDescription&DataInputs="+System.args+"&RawDataOutput=Result",
	    complete: function(xml,status) {
		if(checkWPSResult(xml,false)){
		    var colModel=[];
		    var fields=[];
		    var tmp=eval(xml.responseText);
		    for(i=0;i<tmp.length;i++){
			if(i==0)
			    System.pkey=tmp[i][1];
			colModel[i]={display: tmp[i][1], name : tmp[i][1], width: (i==0?80:120), sortable : true, align: 'center'};
			fields[i]=tmp[i][1];
			if(tmp[i][3]=="PRI")
			    System.pkey=tmp[i][1];
		    }
		    
		    if($("#pg_table_display")[0])
			$("#flexPG").remove();
		    $("#"+System.tbld).append('<table id="pg_table_display"></table>');
		    var buttons=[ {
			    name : System.messages['Add'],
			    bclass : 'add',
			    onpress : MapMintDBManager.editTuple
			},{
			    name : System.messages['Edit'],
			    bclass : 'edit',
			    onpress : MapMintDBManager.editTuple,
			    onselect: true
			},{
			    name : System.messages['Delete'],
			    bclass : 'delete',
			    onpress : MapMintDBManager.deleteTuple,
			    onselect: true
			}];
		    if(System.table==System.sql_prefix+"servers"){
			buttons=[ {
			    name : System.messages['Privileges'],
			    bclass : 'privileges',
			    onpress : MapMintDBManager.ogcInformations,
			    onselect: true
			},{
			    name : System.messages['Add'],
			    bclass : 'add',
			    onpress : MapMintDBManager.editTuple
			},{
			    name : System.messages['Edit'],
			    bclass : 'edit',
			    onpress : MapMintDBManager.editTuple,
			    onselect: true
			},{
			    name : System.messages['Delete'],
			    bclass : 'delete',
			    onpress : MapMintDBManager.deleteTuple,
			    onselect: true
			}];
		    }
		    $("#pg_table_display").flexigrid({
			autoload: true,
			ogcProtocol: "MM",
			url: System.zooUrl+"?metapath=datastores/postgis&service=WPS&version=1.0.0&request=Execute&Identifier=getTableContent&RawDataOutput=Result&DataInputs="+System.args,
			id: "PG",
			singleSelect: true,
			buttons : buttons,
			dataType: 'json',
			colModel: colModel,
			usepager: true,
			sortname: tmp[0][1],
			sortorder: "asc",
			fields: fields,
			searchitems: colModel,
			dwDataSource: System.dataStore,
			dwLayer: System.table,
			title: System.table,
			useLimit: true,
			limit: 10,
			showTableToggleBtn: true,
			width: "100%",
			height: 290 
			
		    });
		}
	    }
	});
		
    },
	    
    
  initializeAddWindow: function(){
      var dsType=arguments[0];
      var dsName=arguments[1];
      if(!Distiller.windows["add-database-dialog"]){
	  $.ajax({
	      type: "GET",
	      url: System.zooUrl+"?metapath=template&service=WPS&version=1.0.0&request=Execute&Identifier=display&DataInputs=tmpl=Distiller_db_display&RawDataOutput=Result",
	      dataType: "text",
	      complete: function(xml,status) {
		  try{
		      $( 'body').append(xml.responseText);
		      if(!Distiller.windows)
			  Distiller.windows={};
		      if(!Distiller.windows["add-database-dialog"]){
			  Distiller.windows["add-database-dialog"]=true;
			  $( "#add-database-dialog" ).window({
			      minimizable:false,
			      maximizable:false,
			      resizable: false
			  });
			  $("#dlg-buttons a").button();
	              }
		      if(dsName!=null && dsType!=null){
			  $.ajax({
			      type: "GET",
			      url: System.zooUrl+"?metapath=datastores/postgis&service=WPS&version=1.0.0&request=Execute&Identifier=load&DataInputs=type="+dsType+";name="+dsName+"&RawDataOutput=Result",
			      dataType: "text",
			      complete: function(xml,status) {
				  try{
				      var tmp=eval('('+xml.responseText+')');
				      loadFormWithObject("Distiller.pgisform",
							 Array("name","dbname","host","port",
							       "password","user","stype"),
							 tmp);
				  }catch(e){alert(e);}
			      }
			  });
		      }else{
			  loadFormWithObject("Distiller.pgisform",
					     Array("name","dbname","host","port",
						   "password","user","stype"));
		      }
		  }catch(e){alert(e);}
	      }
          });
      }else{
	  $( "#add-database-dialog" ).window({
	      minimizable:false,
	      maximizable:false,
	      resizable: false
	  });
	  if(dsName!=null && dsType!=null){
	      $.ajax({
		  type: "GET",
		  url: System.zooUrl+"?metapath=datastores/postgis&service=WPS&version=1.0.0&request=Execute&Identifier=load&DataInputs=type="+dsType+";name="+dsName+"&RawDataOutput=Result",
		  dataType: "text",
		  complete: function(xml,status) {
		      try{
			  var tmp=eval('('+xml.responseText+')');
			  loadFormWithObject("Distiller.pgisform",
					     Array("name","dbname","host","port",
						   "password","user","stype"),
					     tmp);
		      }catch(e){alert(e);}
		  }
	      });
	  }else{
	      loadFormWithObject("Distiller.pgisform",
				 Array("name","dbname","host","port",
				       "password","user","stype"));
	}
      }
  },
    
    commit: function(){
	if (arguments[0]=='cancel'){
	    confirm('Delete ' + $('.trSelected',grid).length + ' items?');
	}
	else if (arguments[0]=='add'){
	    $.ajax({
		type: "GET",
		url: System.zooUrl+"?metapath=datastores/postgis&service=WPS&version=1.0.0&request=Execute&Identifier=save&DataInputs=name="+$mj("Distiller.pgisform.name").value+";dbname="+$mj("Distiller.pgisform.dbname").value+";user="+$mj("Distiller.pgisform.user").value+";password="+$mj("Distiller.pgisform.password").value+";host="+$mj("Distiller.pgisform.host").value+";port="+$mj("Distiller.pgisform.port").value+";type="+$mj("Distiller.pgisform.stype").value,
		dataType: "xml",
		complete: function(xml,status) {
		    $('#add-database-dialog').window('close');
		    MapMintDBManager.refresh($mj("Distiller.pgisform.stype").value);
		}
	});
	}
  },
    
    refresh: function(){
	var localArg=arguments[0];
	$.ajax({
	    type: "GET",
	    url: System.zooUrl+"?metapath=datastores/postgis&service=WPS&version=1.0.0&request=Execute&Identifier=displayJson&DataInputs=type="+arguments[0]+"&RawDataOutput=Result",
	    dataType: "xml",	
	    complete: function(xml,status) {
		$('#progress_bar .ui-progress').css('width', '65%');
		var tmp=null;
		try{
		    tmp=eval("("+xml.responseText+")");
		}catch(e){}
		var myData=[];
		if(tmp!=null)
		    for(var i=0;i<tmp.sub_elements.length;i++){
			myData[i]={id: "browseDirectoriesList"+tmp.sub_elements[i].name, text: tmp.sub_elements[i].name, state: "open"};
		    }
		var child;
		var stype=(tmp==null?((localArg=="PostGIS")?"postgisList":(localArg=="MySQL"?"mysqlList":"")):((tmp.name=="PostGIS")?"postgisList":(tmp.name=="MySQL"?"mysqlList":"")));
		child=$("#browser").tree('getChildren',$("#browser").tree('find',stype).target);
		try{
		    $("#browser").tree('append',{parent: $("#browser").tree('find',stype).target,data: myData});
		}catch(e){}
		for(i=0;i<child.length;i++){
		    $("#browser").tree('remove',child[i].target);
		}
		$('#progress_bar .ui-progress').animateProgress(100, function() {
		    $('#progress_bar .ui-progress').fadeOut(1000);
		});
	    }
	});
    },
    
    test: function(){
	$.ajax({
	    type: "GET",
	    url: System.zooUrl+"?metapath=datastores/postgis&service=WPS&version=1.0.0&request=Execute&Identifier=test&DataInputs=name="+$mj("Distiller.pgisform.name").value+";dbname="+$mj("Distiller.pgisform.dbname").value+";user="+$mj("Distiller.pgisform.user").value+";password="+$mj("Distiller.pgisform.password").value+";host="+$mj("Distiller.pgisform.host").value+";port="+$mj("Distiller.pgisform.port").value+";type="+$mj("Distiller.pgisform.stype").value+"&RawDataOutput=Result",
	    dataType: "text",
	    complete: function(xml,status) {
		checkWPSResult(xml);
	    }
	});
    },

    remove: function(){
	dsType=$mj("Distiller.pgisrform.stype").value;
	$.ajax({
	    type: "GET",
	    url: System.zooUrl+"?metapath=datastores/"+((dsType=='postgis' || dsType=='mysql')?"postgis":((dsType=='WMS' || dsType=='WFS')?"wfs":"directories"))+"&service=WPS&version=1.0.0&request=Execute&Identifier=delete&DataInputs=name="+$mj("Distiller.pgisrform.name").value+";type="+$mj("Distiller.pgisrform.stype").value,
	    dataType: "text",
	    complete: function(xml,status) {
		if(checkWPSResult(xml,false)){
		    if(dsType=="PostGIS" || dsType=="MySQL")
			MapMintDBManager.refresh($mj("Distiller.pgisrform.stype").value);
		    else
			document.location.reload(true);
		}
	    }
	});
    },

    initializeRemoveWindow: function(){
	var dsType=$('#browser_selected_type').val().replace(/List/,"");
	var dsName=$('#browser_selected_dsName').val().replace(/browseDirectoriesList/,"");
	if(dsType=="PostGIS" || dsType=="MySQL"){
	    dsType=(dsType=="MySQL"?"mysql":"postgis");
	    loadFormWithObject("Distiller.pgisrform",
			       Array("name"));
	}
	if(Distiller.windows["delete-database-dialog"]){
	    $( "#delete-database-dialog" ).window('close');
	    $( "#delete-database-dialog" ).parent().remove();
	}
	
	$.ajax({
	    type: "GET",
	    url: System.zooUrl+"?metapath=template&service=WPS&version=1.0.0&request=Execute&Identifier=display&DataInputs=tmpl=Distiller_db_remove&RawDataOutput=Result",
	    dataType: "text",
	    complete: function(xml,status) {
		$( 'body').append(xml.responseText);
		if(!Distiller.windows)
		    Distiller.windows={};
		Distiller.windows["delete-database-dialog"]=true;
		$( "#delete-database-dialog" ).window({
		    minimizable:false,
		    maximizable:false,
		    resizable: false
		});
		$("#dlgr-buttons a").button();
		loadFormWithObject("Distiller.pgisform",
				   Array("name"));
		$.ajax({
		    type: "GET",
		    url: System.zooUrl+"?metapath=datastores/"+((dsType=="postgis" || dsType=="mysql")?"postgis":((dsType=="wfs" || dsType=="wms")?"wfs":"directories"))+"&service=WPS&version=1.0.0&request=Execute&Identifier=load&DataInputs=type="+dsType+";name="+dsName+"&RawDataOutput=Result",
		    dataType: "text",
		    complete: function(xml,status){
			var tmp=eval('('+xml.responseText+')');
			loadFormWithObject("Distiller.pgisrform",
					   Array("name"),
					   tmp);
			loadFormWithObject("Distiller.pgisrform",
					   Array("stype"),
					   dsType);
		    }
		});
	    }
	});
    }
    
});
